import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from '@/router'
import {SystemRouters} from '@/router'
import store from '@/store'

const whiteList = ['/login', '/401', '/404', '/500'] //不重定向的白名单

router.beforeEach((to, from, next) => {
    NProgress.start() //开启NProgress进度条


    // 生成可访问的路由表
    store.dispatch('GeneratorRouters', SystemRouters).then(() => {
        console.log('执行了多次，重复添加了路由表，加入登陆验证后解决')
        router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
        next(...to)
    })

    next(...to) // hack方法 确保addRoutes已完成
})

router.afterEach(() => {
    NProgress.done() //结束NProgress进度条
})